from django.db import models

# Create your models here.
from django.db import models
from django.contrib import auth
# Create your models here.
from django.utils import timezone

from users.models import User, BaseModel


class Tweet(models.Model):
    user = models.ForeignKey(User, verbose_name='创建用户', on_delete=models.PROTECT, related_name='users_tweet')
    create_time = models.DateTimeField(verbose_name='吐槽时间', default=timezone.now)
    content = models.TextField(verbose_name='吐槽内容')
    is_delete = models.BooleanField(verbose_name='是否删除')
    update_time = models.DateField(default=timezone.now, verbose_name="吐槽更新时间")
    # like_count = models.IntegerField(verbose_name="吐槽点赞次数")
    # collect_count = models.IntegerField(verbose_name="吐槽收藏次数")
    # share_count = models.IntegerField(verbose_name="吐槽分享次数")
    # comment_count = models.IntegerField(verbose_name="评论次数")

    class Meta:
        db_table = 'tweets'
        verbose_name = '吐槽'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.content


class Comment(models.Model):
    user = models.ForeignKey(User, on_delete=models.PROTECT, related_name='user_comments', verbose_name='评论用户')
    create_time = models.DateTimeField(verbose_name='吐槽时间', default=timezone.now)
    content = models.TextField(verbose_name='评论内容')
    is_delete = models.BooleanField(verbose_name='是否删除')
    tweet = models.ForeignKey(Tweet, verbose_name='吐槽id', on_delete=models.PROTECT, related_name='tweets_comment')
    update_time = models.DateField(default=timezone.now, verbose_name="吐槽更新时间")
    # comment_count = models.IntegerField(verbose_name='评论点赞次数')
    # comment_parent = models.ForeignKey('self', verbose_name='父评论id', on_delete=models.SET_NULL, related_name='subs', null=True, blank=True)

    class Meta:
        db_table = 'comments'
        verbose_name = '评论'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.content
